package com.bond.controller;

import com.bond.common.ScanCount;
import com.bond.common.ScanListReq;
import com.bond.common.page.TableDataInfo;
import com.bond.common.util.PageUtils;
import com.bond.entry.DeviceInfo;
import com.bond.entry.ScanReqInfo;
import com.bond.service.SysService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
public class ApiScanController {

    @Autowired
    private SysService sysService;

    @PostMapping("/api/scan/count")
    public TableDataInfo scanCount(DeviceInfo deviceInfo) {
        PageUtils.startPage();
        List<ScanCount> scanCoutList = sysService.scanCout();
        return getDataTable(scanCoutList);
    }

    @PostMapping("/api/scan/list/{deviceId}")
    public TableDataInfo scanLit(@PathVariable String deviceId, ScanListReq scanListReq) {
        PageUtils.startPage();
        scanListReq.setDeviceId(deviceId);
        List<ScanReqInfo> scanReqInfoList = sysService.scanlist(scanListReq);
        return getDataTable(scanReqInfoList);
    }

//    /**
//     * 查询人员扫码统计
//     */
//    @GetMapping("/api/scanCount")
//    public ModelAndView scanCount(ModelAndView modelAndView) {
//        List<ScanCount> scanCoutList = sysService.scanCout();
//        modelAndView.setViewName("scancount");
//        modelAndView.addObject("scanCoutList", scanCoutList);
//        return modelAndView;
//    }
//
//    /**
//     * 查询人员扫码详细列表
//     */
//    @GetMapping("/api/scanlist")
//    public ModelAndView scanlist(String deviceId, ModelAndView modelAndView) {
//        List<ScanReqInfo> scanReqInfoList = sysService.scanlist(deviceId);
//        modelAndView.setViewName("scanlist");
//        modelAndView.addObject("scanReqInfoList", scanReqInfoList);
//        return modelAndView;
//    }

    /**
     * 响应请求分页数据
     */
    @SuppressWarnings({"rawtypes", "unchecked"})
    protected TableDataInfo getDataTable(List<?> list) {
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }
}
